package com.time.toupdate.Job;

import com.time.toupdate.mapper.BankMapper;
import com.time.toupdate.pojo.Bank;
import com.time.toupdate.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

/**
 * Author:B
 * Description: job 等着备用
 */
@Slf4j
public class InsertJob extends QuartzJobBean {

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Trigger trigger = jobExecutionContext.getTrigger();
        System.out.println(new Date());
        System.out.println("执行定时任务");
        BankMapper bankMapper = SpringContextHolder.getBean(BankMapper.class);
        try {
//            Bank bank = new Bank();
//            bank.setBankname("银行1");
//            bankMapper.insert(bank);
            System.out.println("定时任务执行成功！");
        }catch (Exception e){
            throw new JobExecutionException("定时任务执行失败！");
        }
    }
}